package com.zhku.orders.api;

import com.baomidou.mybatisplus.extension.api.R;
import com.zhku.base.model.PageParams;
import com.zhku.base.model.PageResult;
import com.zhku.base.model.RestResponse;
import com.zhku.orders.model.dto.QueryShopOrder;
import com.zhku.orders.model.dto.QueryUserOrder;
import com.zhku.orders.model.dto.ReturnHotGoodsDto;
import com.zhku.orders.model.dto.ReturnShopOrdersDto;
import com.zhku.orders.model.po.TtOrders;
import com.zhku.orders.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "除支付订单外其他订单接口",tags = "除支付订单外其他订单接口")
@RestController
public class TtOrderController {

    @Autowired
    OrderService orderService;

//    @ApiOperation("通用查询订单接口")
//    @GetMapping("/commonOrder/{id}")
//    public RestResponse<TtOrders> getUserOrder(@PathVariable("id") String id){
//        TtOrders ttOrders = orderService.getUserOrder(id);
//        return RestResponse.success(ttOrders);
//    }

    @ApiOperation("分页当前用户的所有订单")
    @PostMapping("/userOrder/list")
    public PageResult<TtOrders> list(PageParams pageParams, @RequestBody(required = false) QueryUserOrder queryUserOrder){
        PageResult<TtOrders> ordersPageResult = orderService.queryUserOrderList(pageParams, queryUserOrder);
        return ordersPageResult;
    }

    @ApiOperation("分页当前店铺的所有订单")
    @PostMapping("/shopOrder/list")
    public PageResult<ReturnShopOrdersDto> list(PageParams pageParams, @RequestBody(required = false) QueryShopOrder queryShopOrder){
        PageResult<ReturnShopOrdersDto> ordersPageResult = orderService.queryShopOrderList(pageParams, queryShopOrder);
        return ordersPageResult;
    }

    @ApiOperation("查看最热门的十大商品")
    @PostMapping("hotGoodsList")
    public PageResult<ReturnHotGoodsDto> hotGoodsList(){
        PageResult<ReturnHotGoodsDto> hotGoodsList = orderService.getHotGoodsList();
        return hotGoodsList;
    }

    @ApiOperation("超出预期时间，删除订单")
    @PostMapping("/deleteTimeOutOrder/{id}")
    public RestResponse deleteTimeOutOrder(@PathVariable("id")String id){
        orderService.deleteTimeOutOrder(id);
        return RestResponse.success();
    }

    @ApiOperation("查看用户是否支付订单")
    @PostMapping("/payGoods/{payNo}")
    public RestResponse<Boolean> payGoods(@PathVariable("payNo")String payNo){
        Boolean flag = orderService.payGoods(payNo);
        return RestResponse.success(flag);
    }
}
